#include "cpp-httplib/httplib.h"
#include "searcher.hpp"

const std::string root_path = "wwwroot";
const std::string input = "data/raw_html/raw.txt";

int main()
{
    ns_searcher::Searcher search;
    search.InitSearcher(input);

    httplib::Server svr;
    svr.set_base_dir(root_path.c_str());
    svr.Get("/s", [&search](const httplib::Request &req, httplib::Response &res){
        if (!req.has_param("word"))
        {
            res.set_content("搜索内容不能为空！", "text/plain: charset=utf-8");
            return;
        }
        std::string word = req.get_param_value("word");
        std::cout << "正在搜索：" << word << std::endl;
        std::string json_string;
        search.Search(word, &json_string);
        res.set_content(json_string.c_str(), "application/json");

    });
    svr.listen("0.0.0.0", 8085);
    return 0;
}